var insert_pre_rule = JSON.parse('{"CODE":0, "ACTION":"","LEVEL":"T1", "MSG":"","DATA":"","SCRIPTNAME":"insert_pre_rule"}');

var itemNbrList = [];
if (!isNull(LIST)) {
    itemNbrList = getUniqueValues(LIST, "item_nbr");
}

// 获取门店城市对应关系
var store_trait = new Map();
// 获取门店JD对应关系
var store_jd = new Map();
// 获取城市门店对应关系 多个为数组
var trait_store = new Map();
var trait_store_obj = [];
// 所有jd店
var all_store_jd = [];
var store_trait_url = "https://mdc-dev-aloha-gateway.cn.wal-mart.com/price-change/external/cityClubList";
var store_trait_result = JSON.parse(func_post(store_trait_url, {}));


for (var i1 = 0; i1 < store_trait_result.result.length; i1++) {
    var resultElement = store_trait_result.result[i1];
    store_trait.put(resultElement.club, resultElement.cityCode);
    if (!isNull(resultElement.jdstore)) {
        store_jd.put(resultElement.club, resultElement.jdstore);
        var jdstoreSplit = resultElement.jdstore.split(',')
        for (var jdindex in jdstoreSplit) {
            all_store_jd.push(jdstoreSplit[jdindex]);
        }
    }
    var flg = false;
    for (var elm in trait_store_obj) {
        if (trait_store_obj[elm].cityCode === resultElement.cityCode) {
            flg = true;
            trait_store_obj[elm].club.push(resultElement.club);
        }
    }
    if (!flg) {
        var obj = {
            cityCode: resultElement.cityCode,
            club: [resultElement.club]
        }
        trait_store_obj.push(obj);
    }
}

for (var i in trait_store_obj) {
    trait_store.put(trait_store_obj[i].cityCode, trait_store_obj[i].club)
}
//pre_rule.MSG = all_store_jd;
var currentTraitToStoreList = [];
if (!isNull(trait_nbr) && !isNull(trait_store)) {
    if (trait_nbr.toUpperCase() === "ALL") {
        var allTraitStoreList = trait_store.values();
        for (var allTr1 = 0; allTr1 < allTraitStoreList.length; allTr1++) {
            var storeListElement = allTraitStoreList[allTr1];
            currentTraitToStoreList = currentTraitToStoreList.concat(storeListElement);
        }
        // currentTraitToStoreList = allTraitStoreList;
    } else {
        var currentTraitStore = trait_store.get(trait_nbr);
        currentTraitToStoreList = currentTraitToStoreList.concat(currentTraitStore);
    }
} else if (!isNull(store_id)) {
    currentTraitToStoreList.push(store_id)
}

// 商品一品多号接口,大单号,TBFF ,PBDI或DI商品
var item_attributes = new Map();
var item_attributes_param = {
    itemNbrList: itemNbrList
}
var item_attributes_url = "https://mdc-dev-aloha-gateway.cn.wal-mart.com/spp-price-change/server/item-relation/info";
var item_attributes_params = func_sgin(item_attributes_param, "A3D3447D09CA8AA25DF54109B208C3761", "price-change", "usercenter", "1.0.0", "json", "price-change");
var item_attributes_params_target = JSON.parse(item_attributes_params);
item_attributes_params_target.param = item_attributes_param;
var item_attributes_result = func_post(item_attributes_url, JSON.stringify(item_attributes_params_target));
var item_attributes_result_target = JSON.parse(item_attributes_result).result;
var relationMap = new Map();
for (var iart = 0; iart < item_attributes_result_target.length; iart++) {
    var relationItemsList = item_attributes_result_target[iart].relationItems;
    if (!relationMap.containsKey(item_attributes_result_target[iart].itemNbr) && !isNull(relationItemsList)) {
        var reSp = relationItemsList.split(",");
        relationMap.put(item_attributes_result_target[iart].itemNbr,reSp)
    }
}
relationMap.containsValue()
// 一品 多号 productId
// item_attributes.put("productId", item_attributes_result_target.productId);
// 一品 多号 是否 同价 Y / N
// item_attributes.put("isPrice", item_attributes_result_target.isPrice);
// 一品 多号 列表
item_attributes.put("relationItems", item_attributes_result_target.relationItems);
// 大单号
// item_attributes.put("largeOrderItems", item_attributes_result_target.largeOrderItems);
// 是不是 TBFF 商品
// item_attributes.put("tbffFlag", item_attributes_result_target.tbffFlag);
// 是不是 pb 商品
// item_attributes.put("pbdiFlag", item_attributes_result_target.pbdiFlag);
// 是不是 color
// item_attributes.put("color", item_attributes_result_target.color);


JSON.stringify(insert_pre_rule);